#include<bits/stdc++.h>
#define vd void
#define int long long 
#define MAXN 400005 
const int inf=1e18; 
int gi(){
	char c;int x=0,f=0;
	while(!isdigit(c=getchar()))f|=(c=='-');
	while(isdigit(c))x=(x*10)+(c^48),c=getchar();
	return f?-x:x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>vd cxk(T&a,T b){a=a>b?a:b;}
template<class T>vd cnk(T&a,T b){a=a<b?a:b;}
std::set<int>S;
int sum;
int len,a[MAXN],dp[MAXN];
struct node{int l,r;}q[MAXN];
signed main(){
	freopen("kte.in","r",stdin),freopen("kte.out","w",stdout);
	int t=gi();
	bool ok=0;int tot=0; 
	while(t--){
		int x=gi();++tot;
		if(*S.lower_bound(x)==x)S.erase(x),sum-=x;
		else S.insert(x),sum+=x;
		if(S.size()==1){puts("0");continue;}
		auto it=S.begin();int fst=*it;
		int ans2=sum-2*fst;
		if(ok){printf("%lld\n",ans2);continue;}
		int len=0,n=0,sum=0,ans=0;
		for(auto it=S.begin();it!=S.end();it++)a[++n]=*it;
		for(int i=1;i<n;i++)sum+=a[i],q[++len].l=sum;
		sum=len=0;for(int i=n;i>=2;i--)sum+=a[i],q[++len].r=sum-1;
		q[++len]=(node){inf,inf};
		std::sort(q+1,q+len+1,[&](node i,node j){return i.l<j.l;});
		dp[1]=q[1].l;
		for(int i=2;i<=len;i++){
			if(q[i].l<=q[i-1].r)dp[i]=dp[i-1];
			else ans+=q[i-1].r-dp[i-1]+1,dp[i]=q[i].l;
		}
		printf("%lld\n",ans);
		if(ans==ans2&&tot>1000)ok=1;
	}
	return 0;
}
/*
3
567336136308
731658216865
621345981139

328644161114
*/
